﻿using System;
using System.Runtime.Remoting;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Common.Unity.Testing.Objects;
using Microsoft.Practices.Unity;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Testing.Core;
using Common.Unity.Extensions;

namespace Common.Unity.Testing
{
	/// <summary>
	/// Summary description for CommonExtensionTests
	/// </summary>
	[TestClass]
	public class CommonExtensionTests : TestBase
	{
		[TestMethod]
		public void VerifyINamedObjectRegisteredCorrectly()
		{
			Assert.IsTrue( Configuration.Container.IsRegistered<INamedObject>() );
		}

		[TestMethod]
		public void VerifyNamedObjectRegisteredCorrectly()
		{
			Assert.IsTrue( Configuration.Container.IsRegistered<NamedObject>(  ) );
		}

		[TestMethod]
		public void VerifyNamedTypeObjectRegisteredCorrectly()
		{
			Assert.IsTrue( Configuration.Container.IsRegistered<INamedTypeObject>( "Default" ) );
		}
		
		[TestMethod]
		public void VerifyNamedNamedTypeObjectRegisteredCorrectly()
		{
			Assert.IsTrue( Configuration.Container.IsRegistered<NamedTypeObject>( "Normal" ) );
		}

		[TestMethod, Owner( TestOwners.MichaelD_Bang )]
		public void VerifyUnRegisteredTypeReturnsNull()
		{
			Type type = Configuration.Container.ResolveType<object>();
			Assert.IsNull( type );
		}

		[TestMethod, Owner( TestOwners.MichaelD_Bang )]
		public void VerifyRegisteredTypeReturnsSelf()
		{
			Type type = Configuration.Container.ResolveType<NamedObject>();
			Assert.AreEqual( typeof(NamedObject), type );
		}


		[TestMethod, Owner( TestOwners.MichaelD_Bang )]
		public void VerifyTypeResolvesCorrectly()
		{
			Type type = Configuration.Container.ResolveType<INamedObject>();
			Assert.AreEqual( typeof(NamedObject), type );
		}

		[TestMethod, Owner( TestOwners.MichaelD_Bang )]
		public void VerifyNamedTypeResolvesCorrectly()
		{
			Type type = Configuration.Container.ResolveType<INamedTypeObject>( "Default" );
			Assert.AreEqual( typeof(NamedTypeObject), type );
		}

		[TestMethod, Owner( TestOwners.MichaelD_Bang )]
		public void VerifyMappingsResolveCorrectly()
		{
			var types = Configuration.Container.ResolveMappings<NamedObject>().ToArray();
			Assert.AreEqual( 1, types.Length );
			Assert.AreEqual( typeof(INamedObject), types[0] );
		}

		[TestMethod, Owner( TestOwners.MichaelD_Bang )]
		public void VerifyNamedMappingsResolveCorrectly()
		{
			Type[] types = Configuration.Container.ResolveMappings<NamedTypeObject>( "Default" ).ToArray();
			Assert.AreEqual( 1, types.Length );
			Assert.AreEqual( typeof(INamedTypeObject), types[0] );
		}

	}
}
